<?php

namespace app\common\model;

use think\Model;

class Subject extends Model
{

    // 表名
    protected $name = 'subject';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    /**
     * 关联学校表
     *
     * @return void
     */
    public function School()
    {
        return $this->belongsToMany('School', 'school_subject_relation', 'school_id', 'subject_id');
    }
    /** 
     * 列表
     */
    public function dataList($dis, $field = '*', $order = ''){
        $res = $this->where($dis);
        if ($order) {
            $res = $res->order($order);
        }
        if ($field) {
            $res = $res->field($field);
        }
        return $res->select();
    }

    /**
     * 信息
     */
    public function dataInfo($dis, $field = '*', $order = '')
    {
        $res = $this->where($dis);
        if ($order) {
            $res = $res->order($order);
        }
        if ($field) {
            $res = $res->field($field);
        }
        return $res->find();
    }
}